import request from '@/utils/request'
import type { ApiResponse, Channel, ChannelQueryParams, PageResponse } from '@/types/api'

// 栏目管理API
export const channelApi = {
  // 获取栏目树形结构
  getChannelTree(siteId: string | number): Promise<ApiResponse<Channel[]>> {
    return request({
      url: '/admin/channel/tree',
      method: 'get',
      params: { siteId },
    })
  },

  // 分页查询栏目列表
  getChannelPage(params: ChannelQueryParams): Promise<ApiResponse<PageResponse<Channel>>> {
    return request({
      url: '/admin/channel/page',
      method: 'get',
      params,
    })
  },

  // 获取栏目详情
  getChannel(id: string | number): Promise<ApiResponse<Channel>> {
    return request({
      url: `/admin/channel/${id}`,
      method: 'get',
    })
  },

  // 创建栏目
  createChannel(data: Partial<Channel>): Promise<ApiResponse<void>> {
    return request({
      url: '/admin/channel',
      method: 'post',
      data,
    })
  },

  // 更新栏目
  updateChannel(id: string | number, data: Partial<Channel>): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/channel/${id}`,
      method: 'put',
      data,
    })
  },

  // 删除栏目
  deleteChannel(id: string | number): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/channel/${id}`,
      method: 'delete',
    })
  },

  // 更新栏目状态
  updateChannelStatus(id: string | number, status: number): Promise<ApiResponse<void>> {
    return request({
      url: `/admin/channel/${id}/status`,
      method: 'put',
      params: { status },
    })
  },

  // 获取导航栏目
  getNavChannels(siteId: string | number): Promise<ApiResponse<Channel[]>> {
    return request({
      url: '/admin/channel/nav',
      method: 'get',
      params: { siteId },
    })
  },

  // 获取子栏目
  getChildrenChannels(parentId: string | number): Promise<ApiResponse<Channel[]>> {
    return request({
      url: `/admin/channel/${parentId}/children`,
      method: 'get',
    })
  },
}
